
#include <memory.h>

#include "lib.h"

#include "kenopayout.h"
#include "kenoopts.h"

KenoPayout::KenoPayout()
{
	InitPayTables();
	memset(m_paytables, 0, sizeof(int32) * 16 * 16);
}

int32
KenoPayout::GetPayout(int32 picks, int32 catches)
{
	return m_paytables[picks][catches];
}

void 
KenoPayout::InitPayTables()
{
	LoadPayTables();

#if 0
	// Brian: Not sure what this was for
	int32 min = 16;
	int32 max = 1;

	// find the min and max bets
	for(int32 picks = 1; picks < 16; picks++)
	{
		for(int32 catches = 1; catches < 16; catches++)
		{
			// check to see if there is any bet that is not zero for this
			//  number of picks
			if(m_paytables[picks][catches])
			{
				if(picks < min) min = picks;
				if(picks > max) max = picks;
			}
		}
	}

	KenoOpts::SetOpts(min, max);
#endif
}

void
KenoPayout::LoadPayTables()
{
	LoadLowPayTable();
	LoadMedPayTable();
	LoadHighPayTable();
}

void
KenoPayout::LoadHighPayTable()
{
	memset(m_paytable_high, 0, 16 * 16 * sizeof(int32));	

	// pick 1
	m_paytable_high[1][1] = 3;

	// pick 2
	m_paytable_high[2][2] = 15;

	// pick 3
	m_paytable_high[3][2] = 2;
	m_paytable_high[3][3] = 45;
	
	// pick 4
	m_paytable_high[4][2] = 1;
	m_paytable_high[4][3] = 5;
	m_paytable_high[4][4] = 155;

	// pick 5
	m_paytable_high[5][3] = 2;
	m_paytable_high[5][4] = 15;
	m_paytable_high[5][5] = 850;

	// pick 6
	m_paytable_high[6][3] = 1;
	m_paytable_high[6][4] = 6;
	m_paytable_high[6][5] = 111;
	m_paytable_high[6][6] = 2000;

	// pick 7
	m_paytable_high[7][4] = 2;
	m_paytable_high[7][5] = 32;
	m_paytable_high[7][6] = 450;
	m_paytable_high[7][7] = 8000;

	// pick 8
	m_paytable_high[8][5] = 10;
	m_paytable_high[8][6] = 135;
	m_paytable_high[8][7] = 1700;
	m_paytable_high[8][8] = 30000;

	// pick 9
	m_paytable_high[9][5] = 6;
	m_paytable_high[9][6] = 62;
	m_paytable_high[9][7] = 310;
	m_paytable_high[9][8] = 4000;
	m_paytable_high[9][9] = 50000;

	// pick 10
	m_paytable_high[10][5]  = 2;
	m_paytable_high[10][6]  = 26;
	m_paytable_high[10][7]  = 180;
	m_paytable_high[10][8]  = 1200;
	m_paytable_high[10][9]  = 10000;
	m_paytable_high[10][10] = 100000;

	// pick 11
	m_paytable_high[11][6]  = 13;
	m_paytable_high[11][7]  = 100;
	m_paytable_high[11][8]  = 500;
	m_paytable_high[11][9]  = 2500;
	m_paytable_high[11][10] = 25000;
	m_paytable_high[11][11] = 100000;

	// pick 12
	m_paytable_high[12][6] = 6;
	m_paytable_high[12][7] = 45;
	m_paytable_high[12][8] = 270;
	m_paytable_high[12][9] = 1200;
	m_paytable_high[12][10] = 5000;
	m_paytable_high[12][11] = 25000;
	m_paytable_high[12][12] = 100000;

	// pick 13
	m_paytable_high[13][0] = 2;
	m_paytable_high[13][6] = 2;
	m_paytable_high[13][7] = 23;
	m_paytable_high[13][8] = 90;
	m_paytable_high[13][9] = 800;
	m_paytable_high[13][10] = 4500;
	m_paytable_high[13][11] = 15000;
	m_paytable_high[13][12] = 50000;
	m_paytable_high[13][13] = 100000;

	// pick 14
	m_paytable_high[14][0] = 2;
	m_paytable_high[14][6] = 2;
	m_paytable_high[14][7] = 10;
	m_paytable_high[14][8] = 50;
	m_paytable_high[14][9] = 375;
	m_paytable_high[14][10] = 1500;
	m_paytable_high[14][11] = 10000;
	m_paytable_high[14][12] = 25000;
	m_paytable_high[14][13] = 50000;
	m_paytable_high[14][14] = 100000;

	// pick 15
	m_paytable_high[15][0] = 2;
	m_paytable_high[15][7] = 12;
	m_paytable_high[15][8] = 30;
	m_paytable_high[15][9] = 140;
	m_paytable_high[15][10] = 600;
	m_paytable_high[15][11] = 2800;
	m_paytable_high[15][12] = 25000;
	m_paytable_high[15][13] = 50000;
	m_paytable_high[15][14] = 100000;
	m_paytable_high[15][15] = 100000;
}

void
KenoPayout::LoadMedPayTable()
{
	memset(m_paytable_med, 0, 16 * 16 * sizeof(int32));	

	// pick 1
	m_paytable_med[1][1] = 3;

	// pick 2
	m_paytable_med[2][2] = 14;

	// pick 3
	m_paytable_med[3][2] = 2;
	m_paytable_med[3][3] = 40;
	
	// pick 4
	m_paytable_med[4][2] = 1;
	m_paytable_med[4][3] = 4;
	m_paytable_med[4][4] = 150;

	// pick 5
	m_paytable_med[5][3] = 2;
	m_paytable_med[5][4] = 13;
	m_paytable_med[5][5] = 800;

	// pick 6
	m_paytable_med[6][3] = 1;
	m_paytable_med[6][4] = 5;
	m_paytable_med[6][5] = 100;
	m_paytable_med[6][6] = 1800;

	// pick 7
	m_paytable_med[7][4] = 2;
	m_paytable_med[7][5] = 30;
	m_paytable_med[7][6] = 400;
	m_paytable_med[7][7] = 8000;

	// pick 8
	m_paytable_med[8][5] = 10;
	m_paytable_med[8][6] = 120;
	m_paytable_med[8][7] = 1600;
	m_paytable_med[8][8] = 30000;

	// pick 9
	m_paytable_med[9][5] = 5;
	m_paytable_med[9][6] = 60;
	m_paytable_med[9][7] = 300;
	m_paytable_med[9][8] = 4000;
	m_paytable_med[9][9] = 50000;

	// pick 10
	m_paytable_med[10][5] = 2;
	m_paytable_med[10][6] = 25;
	m_paytable_med[10][7] = 150;
	m_paytable_med[10][8] = 1200;
	m_paytable_med[10][9] = 10000;
	m_paytable_med[10][10] = 100000;

	// pick 11
	m_paytable_med[11][6] = 10;
	m_paytable_med[11][7] = 100;
	m_paytable_med[11][8] = 500;
	m_paytable_med[11][9] = 2500;
	m_paytable_med[11][10] = 25000;
	m_paytable_med[11][11] = 100000;

	// pick 12
	m_paytable_med[12][6] = 5;
	m_paytable_med[12][7] = 40;
	m_paytable_med[12][8] = 250;
	m_paytable_med[12][9] = 1200;
	m_paytable_med[12][10] = 5000;
	m_paytable_med[12][11] = 25000;
	m_paytable_med[12][12] = 100000;

	// pick 13
	m_paytable_med[13][0] = 2;
	m_paytable_med[13][6] = 2;
	m_paytable_med[13][7] = 22;
	m_paytable_med[13][8] = 85;
	m_paytable_med[13][9] = 600;
	m_paytable_med[13][10] = 3700;
	m_paytable_med[13][11] = 12000;
	m_paytable_med[13][12] = 50000;
	m_paytable_med[13][13] = 100000;

	// pick 14
	m_paytable_med[14][0] = 2;
	m_paytable_med[14][6] = 2;
	m_paytable_med[14][7] = 10;
	m_paytable_med[14][8] = 45;
	m_paytable_med[14][9] = 350;
	m_paytable_med[14][10] = 1100;
	m_paytable_med[14][11] = 8000;
	m_paytable_med[14][12] = 25000;
	m_paytable_med[14][13] = 50000;
	m_paytable_med[14][14] = 100000;

	// pick 15
	m_paytable_med[15][0] = 2;
	m_paytable_med[15][7] = 12;
	m_paytable_med[15][8] = 30;
	m_paytable_med[15][9] = 120;
	m_paytable_med[15][10] = 300;
	m_paytable_med[15][11] = 2800;
	m_paytable_med[15][12] = 25000;
	m_paytable_med[15][13] = 50000;
	m_paytable_med[15][14] = 100000;
	m_paytable_med[15][15] = 100000;
}

void
KenoPayout::LoadLowPayTable()
{
	memset(m_paytable_low, 0, 16 * 16 * sizeof(int32));	

	// pick 1
	m_paytable_low[1][1] = 3;

	// pick 2
	m_paytable_low[2][2] = 12;

	// pick 3
	m_paytable_low[3][2] = 1;
	m_paytable_low[3][3] = 43;
	
	// pick 4
	m_paytable_low[4][2] = 1;
	m_paytable_low[4][3] = 3;
	m_paytable_low[4][4] = 130;

	// pick 5
	m_paytable_low[5][3] = 1;
	m_paytable_low[5][4] = 10;
	m_paytable_low[5][5] = 800;

	// pick 6
	m_paytable_low[6][3] = 1;
	m_paytable_low[6][4] = 4;
	m_paytable_low[6][5] = 95;
	m_paytable_low[6][6] = 1500;

	// pick 7
	m_paytable_low[7][4] = 1;
	m_paytable_low[7][5] = 25;
	m_paytable_low[7][6] = 350;
	m_paytable_low[7][7] = 8000;

	// pick 8
	m_paytable_low[8][5] = 9;
	m_paytable_low[8][6] = 90;
	m_paytable_low[8][7] = 1500;
	m_paytable_low[8][8] = 25000;

	// pick 9
	m_paytable_low[9][5] = 4;
	m_paytable_low[9][6] = 50;
	m_paytable_low[9][7] = 280;
	m_paytable_low[9][8] = 4000;
	m_paytable_low[9][9] = 50000;

	// pick 10
	m_paytable_low[10][5] = 1;
	m_paytable_low[10][6] = 22;
	m_paytable_low[10][7] = 150;
	m_paytable_low[10][8] = 1000;
	m_paytable_low[10][9] = 5000;
	m_paytable_low[10][10] = 100000;

	// pick 11
	m_paytable_low[11][6] = 8;
	m_paytable_low[11][7] = 80;
	m_paytable_low[11][8] = 400;
	m_paytable_low[11][9] = 2500;
	m_paytable_low[11][10] = 25000;
	m_paytable_low[11][11] = 100000;

	// pick 12
	m_paytable_low[12][6] = 5;
	m_paytable_low[12][7] = 32;
	m_paytable_low[12][8] = 200;
	m_paytable_low[12][9] = 1000;
	m_paytable_low[12][10] = 5000;
	m_paytable_low[12][11] = 25000;
	m_paytable_low[12][12] = 100000;

	// pick 13
	m_paytable_low[13][0] = 1;
	m_paytable_low[13][6] = 1;
	m_paytable_low[13][7] = 20;
	m_paytable_low[13][8] = 80;
	m_paytable_low[13][9] = 600;
	m_paytable_low[13][10] = 3500;
	m_paytable_low[13][11] = 10000;
	m_paytable_low[13][12] = 50000;
	m_paytable_low[13][13] = 100000;

	// pick 14
	m_paytable_low[14][0] = 1;
	m_paytable_low[14][6] = 1;
	m_paytable_low[14][7] = 9;
	m_paytable_low[14][8] = 42;
	m_paytable_low[14][9] = 310;
	m_paytable_low[14][10] = 1100;
	m_paytable_low[14][11] = 8000;
	m_paytable_low[14][12] = 25000;
	m_paytable_low[14][13] = 50000;
	m_paytable_low[14][14] = 100000;

	// pick 15
	m_paytable_low[15][0] = 1;
	m_paytable_low[15][7] = 10;
	m_paytable_low[15][8] = 25;
	m_paytable_low[15][9] = 100;
	m_paytable_low[15][10] = 300;
	m_paytable_low[15][11] = 2800;
	m_paytable_low[15][12] = 25000;
	m_paytable_low[15][13] = 50000;
	m_paytable_low[15][14] = 100000;
	m_paytable_low[15][15] = 100000;
}

void 
KenoPayout::SetPayTable(int32 paytable) 
{ 
	if(paytable >= 0 && paytable <= 2)
	{
		m_paytable = paytable; 
		switch(m_paytable)
		{
			case LOW:
				memcpy(m_paytables, m_paytable_low, sizeof(int32) * 16 * 16);
				break;

			case MEDIUM:
				memcpy(m_paytables, m_paytable_med, sizeof(int32) * 16 * 16);
				break;

			case HIGH:
				memcpy(m_paytables, m_paytable_high, sizeof(int32) * 16 * 16);
				break;
		}
	}
	else
	{
		m_paytable = 0;
	}
}



